package com.fruit.controller.wap.problem;
  
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fruit.controller.base.BaseController;
import com.fruit.pojo.common.Page;
import com.fruit.pojo.problem.Problem;
import com.fruit.service.user.UserManager;
import com.fruit.util.ResultInfo;

import lombok.extern.slf4j.Slf4j;

/**
 * 常见问题
 * 
 * @author Administrator
 * @version 2018.3.28 17:40
 */
@Slf4j
@Controller
@RequestMapping(value = "/wap/problem")
public class ProblemControllerWap extends BaseController {
	
	@Autowired
	private UserManager userService;
    
	/**
	 * 常见问题列表
	 * @param Page page
	 * @return Map<String, Object>
	 */
	@RequestMapping(value = "/getProblemList", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Map<String, Object> getProblemList(Page page) {
		log.info("【常见问题列表】---【开始】");
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			Map<String, Object> pam = new HashMap<String, Object>();
			pam.put("start", (page.getPage() - 1) * page.getShowNum());
			pam.put("num", page.getShowNum());
			Map<String,Problem> problemList= userService.getProblemList(pam);
			result.put("problemList", problemList);
			result.put("result", this.initResult(ResultInfo.SUCCESS, "ok", "获取成功！"));
		} catch (Exception e) {
			log.info("【常见问题列表】---【异常】---{}", e);
			result.put("result", this.initResult(ResultInfo.ERROR, "exception", "网络异常"));
		}
		log.info("【常见问题列表】---【结束】--");
		return result;
	}
	
	/**
	 * 常见问题详情
	 * @param Page page
	 * @param Integer id
	 * @return Map<String, Object>
	 */
	@RequestMapping(value = "/getProblemDetails", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Map<String, Object> getProblemDetails(Integer id, Page page) {
		log.info("【常见问题详情】---【开始】");
		Map<String, Object> result = new HashMap<String, Object>();
		if(id == null){
			result.put("result", this.initResult(ResultInfo.ERROR, "ERROR", "参数错误！"));
			return result;
		}
		try {
			Map<String, Object> pam = new HashMap<String, Object>();
			pam.put("start", (page.getPage() - 1) * page.getShowNum());
			pam.put("num", page.getShowNum());
			pam.put("id", id);
			List<Map<String,Object>> problemList= userService.getProblemDetails(pam);
			result.put("problemList", problemList);
			result.put("result", this.initResult(ResultInfo.SUCCESS, "ok", "获取成功！"));
		} catch (Exception e) {
			log.info("【常见问题详情】---【异常】---{}", e);
			result.put("result", this.initResult(ResultInfo.ERROR, "exception", "网络异常"));
		}
		log.info("【常见问题详情】---【结束】--");
		return result;
	}
}
